package net.skyedu.service.myattend;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.Attendance;
import net.skyedu.dao.UserInfoDao;

public class Upconfirm extends HttpServlet {

	private static final long serialVersionUID = -8296275310157004285L;

	/**
	 * Constructor of the object.
	 */
	public Upconfirm() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String attId=request.getParameter("attID");
		String status=request.getParameter("status");
		String currentPage=request.getParameter("currentPage");
		UserInfoDao ud=new UserInfoDao();
		Attendance att=new Attendance();
		att.setAttconfirm(1);
		att.setAttupdatestate(4);
		
		int num = ud.updateConfirm(att,attId);
		if(num > 0){
			request.getRequestDispatcher("MonthUser?sta="+status+"&currentPage="+currentPage).forward(request, response);
		}else{
			out.print("<script type='text/javascript'>alert('Error:102,Failure to identify!');history.go(-1);</script>");
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
